package com.wuzuqing.android.eightdiagrams

import android.graphics.Color
import android.widget.TextView
import com.wuzuqing.android.eightdiagrams.base.BaseAdapter
import com.wuzuqing.android.eightdiagrams.base.BaseViewHolder
import com.wuzuqing.android.eightdiagrams.model.City

/**
 * @CopyRight: 广州仰望星空云科技有限公司
 * @Author : wuzuqing
 * @Email:wuzuqing@xinyu668.com
 * @CreateTime: 8.12.23 2:22 PM
 * @Description: 请写描述
 */
class ProvinceAdapter : BaseAdapter<String>(android.R.layout.simple_list_item_1) {
    var lastSelectIndex = 0
    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        holder.getView<TextView>(android.R.id.text1).text = getItem(position)
        holder.itemView.setBackgroundColor(
            if (position == lastSelectIndex)
                Color.parseColor("#aa132542") else Color.TRANSPARENT
        )
    }

    override fun onClickPosition(position: Int) {
        super.onClickPosition(position)
        val oldPosition = lastSelectIndex
        lastSelectIndex = position
        notifyItemChanged(position)
        notifyItemChanged(oldPosition)
    }

}

class CityAdapter : BaseAdapter<City>(android.R.layout.simple_list_item_1) {

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        holder.getView<TextView>(android.R.id.text1).text = getItem(position)?.city.orEmpty()
    }
}

